fix(providers/claude): initialize options.hooks before per-node hook merge#1308
fix(providers/claude): initialize options.hooks before per-node hook merge#1308tharting777 wants to merge 1 commit intocoleam00:devfrom
Conversation
…merge
applyNodeConfig's merge loop writes into options.hooks without guaranteeing
it is defined. When a workflow declares per-node hooks (e.g. archon-architect,
archon-refactor-safely) and the SDK options arrive with hooks unset, the
cast-based assignment crashes with:
TypeError: undefined is not an object (evaluating 'options.hooks[event] = matchers')
at applyNodeConfig (packages/providers/src/claude/provider.ts:394)
The same function acknowledges options.hooks may be undefined one line above
(existingHooks typed as SDKHooksMap | undefined), so the fix is to materialize
the object before the write loop runs.
Add options.hooks ??= {}; after the existingHooks capture — the capture still
references the pre-init value, the merge path's semantics are unchanged when
hooks already exist (no-op), and the else branch that previously crashed now
populates the freshly-initialized map.
Add a regression test that drives sendQuery with a nodeConfig.hooks payload
and asserts the SDK receives options.hooks populated. The test fails with
the original TypeError on the unpatched code.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe changes add defensive initialization logic to the Claude provider's Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
applyNodeConfigwrites intooptions.hooks[event]without guaranteeing the hooks map is initialized. Any workflow that declares per-nodehooks(e.g.archon-architect,archon-refactor-safely) crashes at runtime with:```
TypeError: undefined is not an object (evaluating 'options.hooks[event] = matchers')
at applyNodeConfig (packages/providers/src/claude/provider.ts:394)
at sendQuery (packages/providers/src/claude/provider.ts:934)
```
The function explicitly acknowledges
options.hooksmay be undefined one line above (existingHookstyped asSDKHooksMap | undefined), so the fix is to materialize the object before the write loop runs.Reproduction (pre-fix)
Run any workflow with per-node hooks against the Claude provider — the first AI node crashes in
applyNodeConfig. Real-world impact:archon-architectdies on theanalyzenode;archon-refactor-safelyfails identically.Fix
Why this is safe
existingHookscapture so the read semantics are preserved.options.hooksexists:??=is a no-op; the merge-with-existing path runs identically.options.hooksis undefined, it becomes{}, then the loop populates it — exactly what the original code was trying to do.args.options.hooks?.PostToolUseinprovider.test.ts:1113), so callers already handle a potentially-absenthooks.Alternatives considered
options.hooks = {}at the top ofapplyNodeConfig— changes the contract whennodeConfig.hooksis absent (currently leavesoptions.hooksuntouched).Test plan
provider.test.tsdrivessendQuerywithnodeConfig.hooksand asserts the SDK receivesoptions.hookspopulated. The test fails with the original TypeError on unpatched code (verified by stashing the fix and rerunning).bun run testforpackages/providers: 69 pass, 0 fail.bun run type-check— all 10 packages pass.bun run lint— clean.bun run format— no changes required.Happy to adjust wording or expand tests — this surfaced while running
archon-architectagainst an unrelated repo.Summary by CodeRabbit
Bug Fixes
Tests